package pe.epagos.test.junit;

import java.io.IOException;


import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import pe.epagos.test.json.TransactionRequest;
import pe.epagos.test.json.TransactionResponse;

public class ClienteCore {
	private TransactionRequest trxreq= new TransactionRequest();
	public Boolean invocarCore() throws  IOException{
		Boolean retorna= false;
		try{
			
			Gson gson = new GsonBuilder().setPrettyPrinting().create();
			String output = gson.toJson(trxreq);
			
			ClientRequest clientRequest = new ClientRequest("http://localhost:8080/ecore/interfaces/rest/postTransaction");
			clientRequest.accept("application/json");
			clientRequest.body("application/json", output);
			
			ClientResponse<String> clientResponse = clientRequest.post(String.class);
			//System.out.println("response"+clientResponse.getEntity());
			
			TransactionResponse transactionResponse = gson.fromJson(clientResponse.getEntity(), TransactionResponse.class);
					
			retorna=transactionResponse.isSuccess();
			
		}catch(Exception e) {
			System.out.println(e.getMessage());
		} 
		
		
		return retorna;
	}
	public void setParametros(String accountId, int purchaseNumber, double ammount){
		
		trxreq.setAccountId(accountId);
		trxreq.setPurchaseNumber(purchaseNumber);
		trxreq.setAmmount(ammount);
	}
}
